<template>
	<view class="contents">
		<!-- [5].includes(this.identity) -->
		<block v-if="[5].includes(this.identity)">
			<worker ref="worker"/>
		</block>
		<block v-else>
			<view class="centers">
				<view class="header">
					<view class="left_part">
						<view class="title">账户余额（元）</view>
						<view class="money" v-if="detaile">¥ {{detaile.amount || 0}}
						</view>
					</view>
					<view class="right_part" @click="fund">提现</view>
				</view>
				<view class="bottom">
					<!-- 	<view class="stream">
						<view class="">昨日收益(元)</view>
						<view class="price" v-if="detaile">{{detaile.dayEarnings || 0}}</view>
					</view> -->
					<view class="stream" @click="toAll(1)">
			
						<view class="">审核中</view>
						<!-- 昨日收益 -->
						<view class="price" v-if="detaile">{{detaile.waitSettlement || 0}}</view>
					</view>
					<view class="stream" @click="toAll(2)">
						<view class="">待提现</view>
						<!-- 待结算 -->
						<view class="price" v-if="detaile">{{detaile.toBeWithdrawn || 0}}</view>
					</view>
					<view class="stream" @click="toAll(0)">
						<view class="">全部</view>
			
						<!-- 累计收益 -->
						<view class="price" v-if="detaile">{{detaile.sum || 0}}</view>
					</view>
				</view>
				<!-- <view class="stream" v-for="(item,index) in to" :key="index">
					<image class="icon" :src="item.src" mode="" @click="fund(item,index)"></image>
					<view class="">{{item.title}}</view>
				</view> -->
			</view>
			<view class="select_wrap">
				<view class="left_part">
					<picker mode="date" :value="single" fields="month" @change="bindDateChange">
						<input class="pickerclass" :disabled="true" v-model="mySingle" placeholder="请选择月份" />
						<uni-icons style="display: inline-block; position: relative;left: -0rpx;top: -6rpx;z-index: 1;"
							type="arrowdown" color="#333"></uni-icons>
					</picker>
				</view>
				<view class="right_part" v-if="myDetail">
					<text>收入：¥ {{myDetail.monthIncome || 0}}</text>
					<text style="margin-left: 16rpx;">支出：¥ {{myDetail.monthSpending || 0}}</text>
				</view>
			</view>
			<view class="mylist df" v-if="orderList.length>0">
				<view class="" style="width: 98%;">
					<view class="lists" v-for="(item,index) in orderList">
						<view class="" style="border-bottom: 1rpx solid RGBA(229, 229, 229, 1);padding-bottom: 10rpx;">
							<view class="top">
								<view class="lft" style="color: #EA2027;" v-if="item.serviceName.slice(-4)=='提现失败'">
									{{item.serviceName}}
									<uni-icons type="help" style="color: #EA2027;" size="20"
										@click="handleModel(item.recordInfo)"></uni-icons>
								</view>
								<view class="lft" v-else>{{item.serviceName}}</view>
								<view class="rft df" style="color: #d9001b;" :class="{jian: item.type!=1}"><text>
										{{item.type==1? '+' : (item.type==2?'-':'')}}</text>
									{{item.price}}
									<view class="" style="" v-if="item.recordList.length>0"
										@click.stop="handleDetail(index)" :style="">
										<img src="http://loto.oss-cn-shanghai.aliyuncs.com/email/a9e5cd8ca57249c5.png"
											alt="" style="width: 45rpx;height: 32rpx;margin-top: 5rpx;"
											:style="item.showDetail?'transition: transform 0.3s; transform: rotate(180deg);':'transition: transform 0.3s;'">
									</view>
								</view>
			
							</view>
			
							<view class="btm">
								<view class="lft">
									<!-- 审核中 -->
									<block v-if="item.isShow==1">预计到账时间</block>
									{{item.updatedTime}}
								</view>
								<view class="rft">余额：¥ {{item.amount}}</view>
							</view>
			
			
			
							<!-- <view class="msg">{{item.name}}</view>
					<view class="state">
						<view :class=" ['iconfont',item.id?'icon-shenhe':'icon-fuwuzhong']"></view>
						<view class="stateTitle">{{item.id?'等待审核':'服务中'}}</view>
					</view>
					<view class="do" :style="style(item)" @click="todo(item)">{{item.id?'催审核':'填报告'}}</view> -->
						</view>
						<view class="df-wrap" style="justify-content: end;" v-if="item.showDetail">
							<view class="a-bet" style="width: 100%;margin:8rpx 0 8rpx 0"
								v-for="(item2,index2) in item.recordList" :key="index2">
								<view style="width: 100%;" class="">
									<view class="omit" style="font-size: 24rpx;color: #4c4c4c;">
										{{item2.serviceName}}
									</view>
									<!-- 	<view style="color:#7f7f7f">
									{{item2.updatedTime}}
								</view> -->
								</view>
								<view class="" style="color: #d9001b;font-size: 24rpx;">
									+{{item2.price}}
								</view>
							</view>
						</view>
					</view>
				</view>
			
			
			</view>
			<view class="none" v-if="!orderList">
				<image src="../../../static/none/order.png" mode=""></image>
				<view class="">
					暂无订单~
				</view>
			</view>
			<!-- 加载更多 h5端底部导航会遮盖住它 -->
			<view style="background: rgba(216, 216, 216, 0);" v-if="isReachBottom ">
				<uni-load-more :status="more" @clickLoadMore="loadMore"></uni-load-more>
			</view>
			
			<!-- 需执行操作的 confirm -->
			<uni-confirm :show="confirmShow" :title="confirmTitle" :content="confirmContent" :contentColor="contentColor"
				:autoClose="autoClose" :cancelText="cancelText" :cancelColor='cancelColor' :confirmText='confirmText'
				:confirmColor='confirmColor' :showCancel='showCancel' @cancel="bindBtn('cancel')"
				@confirm="bindBtn('confirm')">
			</uni-confirm>
			<Model :bol="flag" @handleFlag="handleFlag"></Model>
		</block>
		
		<!-- 导航栏 -->
		<!-- <free-nav-bar  title="消息"></free-nav-bar> -->
		<!-- 	<view class="nav">
		</view> -->

		<!-- <view class="moneyBox">
			<view class="box" style="position: relative;">
				<view>账户余额(元)</view>
				<text class="money" v-if="!detaile">0</text>
				<text class="money" v-else>{{detaile.amount  || 0}}</text>
				<view class="new" v-show="detaile&&detaile.status==1">
					<image src="../../../static/icon/wallet/new.png" mode=""></image>
				</view>
			</view>
			<view class="box">
				<view>累计收益(元)</view>
				<text class="money" v-if="!detaile">0</text>
				<text class="money" v-else>{{detaile.sum}}</text>
			</view>
		</view> -->
		
	</view>
</template>

<script>
	import worker from './worker.vue'
	import refresh from '@/components/common/refresh/index.vue';
	import freeNavBar from '@/components/common/nav-bar/free-nav-bar.vue';
	import uniConfirm from '@/components/uni-ui/uni-confirm/uni-confirm.vue'
	import uniLoadMore from '@/components/uni-ui/uni-load-more/uni-load-more.vue';
	// import utils from '@/common/js/utils.js'
	import {
		selectWalletInfo,
		urgeCheckNursingRecord,
		selectAllWalletRecords,
		// utils,
	} from '@/apis/wallet/index.js'
	export default {
		components: {
			uniLoadMore,
			uniConfirm,
			worker
		},
		data() {
			return {
				single: '',
				mySingle: '', //指定日期的格式
				flag: false,
				confirmShow: false,
				confirmTitle: '提示', //confirm title
				confirmContent: '', //confirm 内容
				contentColor: '#FF6A00', //confirm 内容颜色
				confirmType: '', // 1未实名 2未认证 3没有密码
				autoClose: false, // confrim点击蒙层可关闭
				cancelColor: '#333333', //取消按钮颜色,
				confirmText: '立即认证', //确定按钮的文字
				confirmColor: '#3c8eff', //确认按钮颜色, 
				cancelText: '稍后认证', //取消按钮文字
				showCancel: true, //是否显示取消按钮
				more: 'loading', //more/loading/noMore
				bol: false,
				pageNum: 1,
				orderList: '', //订单列表
				detaile: null, //钱包基本信息
				myDetail: null, //月份的明细
				isReachBottom: false,
				to: [{
						title: '账户提现',
						src: '../../../static/icon/wallet/tixian.png',
						url: '../../wallet/cash-out/cash-out?amount='
					},
					{
						title: '账户提现1',
						src: '../../../static/icon/wallet/tixian.png',
						url: '../../wallet/cash-out/cash-out?amount='
					},
					{
						title: '收支记录',
						src: '../../../static/icon/wallet/shouzhijilu.png',
						url: '../../wallet/purse/purse'
					},
				],
				state: [{
						type: '填报告',
						value: '服务中',
						icon: 'icon-fuwuzhong',
						state: 0
					},
					{
						type: '催审核',
						value: '等待审核',
						icon: 'icon-shenhe',
						state: 1
					},
				],
				identity: 0,
			}
		},
		onLoad() {
			this.into()
			var datetime = new Date();
			var year = datetime.getFullYear();
			var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
			// var month1 = datetime.getMonth() + 1 
			this.mySingle = year + "年" + month + '月'
			this.single = year + "-" + month

			console.log('日期111111111111111', this.single)
			this.getOrder()

		},
		async onShow() {
			this.identity = this.$store.state.userInfo.identity
			if([5].includes(this.identity)) {
				this.$refs.worker.show()
			}
			this.into()
		},
		//下拉刷新
		onPullDownRefresh() {
			this.isReachBottom = false
			if([5].includes(this.identity)) {
				this.$refs.worker.show()
			}
			this.pageNum = 1
			this.getOrder()
			this.into()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		// 页面触底
		onReachBottom() {
			console.log('页面触底了---');
			if (this.more == 'noMore') return;
			this.isReachBottom = true;
			// 显示加载更多数据
			this.more = 'loading';
			this.pageNum++;
			this.getOrder();
		},
		computed: {
			style() {
				return function(item) {
					var color;
					if (item.id) {
						color = `color: #00B7FF;`
					} else if (!item.id) {
						color = `color: #FF6A00;`
					}
					return color
				}
			}
		},
		
		methods: {
			handleDetail(index) {
				this.orderList[index].showDetail = !this.orderList[index].showDetail
				this.$forceUpdate()
			},
			// 全部、待审核、审核中
			toAll(item) {
				uni.navigateTo({
					url: '../../wallet/wallet-list/wallet-list?isShow=' + item
				})
			},
			//获取钱包基本信息
			async into() {
				let nurseId = this.$store.state.userInfo.id
				let res = await selectWalletInfo({
					nurseId
				})
				console.log('钱包基本信息', this.detaile, nurseId)
				this.detaile = res.object
				if (this.detaile.waitSettlement == 0.00) {
					this.detaile.waitSettlement = 0
				}

			},
			//获取订单列表
			async getOrder() {
				// console.log("11111111111111")
				let res = await selectAllWalletRecords({
					yearMonth: this.single,
					pageSize: 10,
					pageNum: this.pageNum,
					isShow: 0,
				})
				console.log(res, 7777777777777,res.object.pageInfo.list.length)
				if (res.success) {

					console.log('99999999999999999', res, 'trueeeeeeeeeee')
					this.myDetail = {
						...res.object
					}
					let list = res.object.pageInfo.list
					list.forEach((i) => {
						i.showDetail = false
					})
					this.into()
					if (list.length > 0) {
						console.log("触发5",this.isReachBottom)
						if (this.isReachBottom) {
							console.log("触发5",list)
							this.orderList.push(...list)
							console.log('orderList11111111111111.', this.orderList)
							console.log("触发4")
						} else {
							this.orderList = list
							console.log('this.orderList11111111111111.', this.orderList)
						}
					} else {
						if (this.isReachBottom) {
							this.more = 'noMore';
							this.pageNum = 1;
						} else {
							this.orderList = [];
							this.isReachBottom = false;
						}
					}

				} else {
					console.log('失败1111111111')
				}

			},
			//订单操作
			async todo(item) {
				let number = item.number
				if (item.id) {
					let res = await urgeCheckNursingRecord({
						number
					})
					if (res.success) {
						plus.nativeUI.toast('催促成功~')
						// uni.showToast({
						// 	icon: 'none',
						// 	title: '催促成功~'
						// })
					}
				} else if (!item.id) {
					uni.navigateTo({
						url: '../../report/fill-in-report/fill-in-report?number=' + number
					})
				}
			},
			//confirm 确定取消
			async bindBtn(type) {
				console.log(type)
				if (type == 'confirm') {
					if (this.confirmType == 1) {
						uni.navigateTo({
							url: '../../../pages/iden/iden/iden?type=0'
						})
					} else if (this.confirmType == 2) {
						uni.navigateTo({
							url: '../../../pages/iden/iden/careerChoice'
						})
					} else if (this.confirmType == 3) {
						uni.navigateTo({
							url: '../../mine/validate/validate?type=7'
						})
					}
				} else {

				}
				this.confirmShow = false
				this.autoClose = false // confrim点击蒙层可关闭
				this.showCancel = true //是否显示取消按钮
			},
			handleFlag(value) {
				this.flag = !!value
			},
			//点击账户提现操作
			async fund() {
				// console.log(this.detaile, '信息')
				// 未登录-直接跳转到登录页面-产品说的……
				if (!this.$store.state.userInfo.id) {
					let res = await this.$store.dispatch('preLogin')
					if (res) {
						uni.navigateTo({
							url: '../../login-register/one-key-login/one-key-login'
						})
					} else {
						uni.navigateTo({
							url: '../../login-register/login/login'
						})
					}
					return
				}
				// ------------
				// if(!this.$store.state.address){
				// 	this.handleFlag(true)
				// 	return
				// }

				// 未实名认证
				if (!this.$store.state.nameStatus) {
					this.confirmContent = '应相关国家规定，为确保平台信息安全，需进行实名认证才可继续！'
					this.confirmType = 1
					this.confirmShow = true
					// uni.showModal({
					// 	title: '提示',
					// 	content: '应相关国家规定，为确保平台信息安全，需进行实名认证才可继续！',
					// 	cancelText: '稍后认证',
					// 	confirmText: '立即认证',
					// 	confirmColor: '#3C8EFF',
					// 	success: (res) => {
					// 		if (res.confirm) {
					// 			uni.navigateTo({
					// 				url: '../../../pages/iden/iden/iden?type=0'
					// 			})
					// 		}
					// 	}
					// })
					return
				}
				// 未职业资格认证
				if (!this.$store.state.attestStatus) {
					this.confirmContent = '应相关国家规定，为确保平台信息安全，需进行执业资格认证才可继续！'
					this.confirmType = 2
					this.confirmShow = true
					// uni.showModal({
					// 	title: '提示',
					// 	content: '应相关国家规定，为确保平台信息安全，需进行执业资格认证才可继续！',
					// 	cancelText: '稍后认证',
					// 	confirmText: '立即认证',
					// 	confirmColor: '#3C8EFF',
					// 	success: (res) => {
					// 		if (res.confirm) {
					// 			uni.navigateTo({
					// 				url: '../../../pages/iden/iden/iden?type=1'
					// 			})
					// 		}
					// 	}
					// })
					return
				}
				if (!this.detaile || !this.detaile.password) {
					this.confirmShow = true
					this.confirmContent = ''
					this.confirmTitle = '请先设置提现密码'
					this.confirmType = 3
					this.autoClose = true, // confrim点击蒙层可关闭
						this.confirmText = '去设置' //确定按钮的文字
					this.showCancel = false //是否显示取消按钮
					return
				}

				uni.navigateTo({
					url: "../../wallet/cash-out/cash-out?amount=" + this.detaile.amount
				})

			},
			loadMore() {
				console.log('加载更多');
			},
			handleModel(v) {
				uni.showModal({
					title: '温馨提示',
					content: v,
					showCancel: false,
					confirmText: '我知道了',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			bindDateChange(e) {
				let arr = e.detail.value.split('-')
				// let month = arr[1].indexOf('0')==0 ? arr[1] : arr[1].slice(0,1)
				this.mySingle = arr[0] + '年' + arr[1] + '月'
				this.single = e.detail.value
				console.log(e.detail.value)
				this.orderList = []
				this.pageNum = 1
				this.getOrder()
			}
		},


	}
</script>

<style lang="scss" scoped>
	.contents {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(247, 247, 247, 1);
		// background: url(../../../static/icon/wallet/bc-top.png) #F7F7F7 no-repeat;
		background-size: 100% 448rpx;
	}

	.nav {
		width: 750rpx;
		height: 358rpx;
		background-color: rgba(60, 142, 255, 1);
		// background: rgba(237, 237, 237, 0.9);

	}


	.moneyBox {
		width: 100%;
		height: 160rpx;
		display: flex;
		justify-content: space-around;
		text-align: center;
		box-sizing: border-box;
	}


	.box {
		width: 240rpx;
		height: 130rpx;
		color: rgba(255, 255, 255, 0.7);

	}

	.money {
		font-size: 48rpx;
		font-weight: 400;
		height: 74rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		margin-top: 16rpx;
		display: block;
		overflow: hidden; //超出的文本隐藏
		text-overflow: ellipsis; //溢出用省略号显示
		white-space: nowrap; //溢出不换行
	}

	.mylist {
		box-sizing: border-box;
		// position: relative;
		//     top: -40px;
		padding: 0 46rpx;
		background: rgba(255, 255, 255, 1);

	}

	.select_wrap {
		// position: relative;
		//     top: -50px;
		display: flex;
		justify-content: space-between;
		padding: 48rpx 26rpx 0rpx;
		color: #333;

		.left_part {
			display: flex;

			.uni-picker-container {
				display: flex;
				align-items: center;
			}

			.pickerclass {
				display: inline-block;
			}

			input {
				width: 170rpx;
				color: #333;
				font-weight: 600;
				z-index: 999;
			}
		}
	}

	.centers {
		// position: relative;
		// top: -130rpx;
		width: 100%;
		margin: 0 auto;
		padding: 92rpx 50rpx 30rpx;
		box-sizing: border-box;
		color: #FFF;
		background-color: rgba(60, 142, 255, 1);

		.header {
			display: flex;
			justify-content: space-between;
			align-items: flex-end;
			margin-bottom: 58rpx;

			.left_part {
				font-size: 44rpx;
			}

			.right_part {
				font-size: 36rpx;
				padding: 6rpx 36rpx;
				color: rgba(60, 142, 255, 1);
				background: rgba(255, 255, 255, 1);
				border-radius: 32px;
			}
		}

		.bottom {
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		// view class="header">
		// 	<view class="left_part">
		// 		<view class="title">账户余额（元）</view>
		// 		<view class="money">¥5534.79</view>
		// 	</view>
		// 	<view class="right_part">提现</view>
		// </view>
		// <view class="bottom">
		// 	<view class="stream" v-for="(item,index) in to" :key="index">
		// 		<view class="">{{item.title}}</view>
	}


	.stream {
		padding: 0 20rpx 0 20rpx;
		// color: #333;
		text-align: center;
		font-size: 28rpx;

		.price {
			// text-align: center;
			// position: relative;
			// left: -16rpx;
			margin-top: 10rpx;
			font-size: 36rpx;
			font-weight: 500;
		}
	}

	.icon {
		width: 64rpx;
		height: 64rpx;
		margin: 0 auto;
		margin-bottom: 16rpx;
	}

	.lists {
		display: flex;
		flex-direction: column;
		// align-items: center;
		justify-content: center;
		width: 100%;
		// height: 152rpx;
		padding-top: 30rpx;
		border-radius: 8rpx;
		margin: 0 auto;
		// margin-top: 16rpx;

		// padding: 0 46rpx;
		box-sizing: border-box;
		// border-bottom: 1rpx solid RGBA(229, 229, 229, 1);
		font-size: 28rpx;

		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 10rpx;
			color: #333;

			.lft {}

			.rft {
				&.jian {
					color: rgba(234, 32, 39, 1);
				}
			}
		}

		.btm {
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #666;

			.lft {}

			.rft {}
		}

	}

	.msg {
		width: 252rpx;
		height: 40rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #454545;
		line-height: 40rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		margin-right: 36rpx;
	}

	.state {
		width: 166rpx;
		height: 48rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #454545;
		display: flex;
		margin-right: 64rpx;
	}

	.iconfont {
		// font-size: 36rpx;
		display: inline-block;
		margin-right: 6rpx;
	}

	.stateTitle {
		height: 48rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #454545;
		line-height: 48rpx;
		display: block;
	}

	.do {
		width: 84rpx;
		height: 40rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		line-height: 40rpx;
	}

	.none {
		image {
			width: 442rpx;
			height: 354rpx;
			display: block;
			margin: 0 auto;
			display: block;
			margin: 0 auto;
			margin-top: 140rpx;
		}

		view {
			font-size: 36rpx;
			font-weight: 500;
			color: #3E3E3E;
			text-align: center;
			margin-top: 80rpx;
		}
	}

	.new {
		width: 98rpx;
		height: 46rpx;
		background: rgba(255, 255, 255, 0.5);
		border-radius: 23rpx;
		position: absolute;
		right: -60rpx;
		top: 0;
		text-align: center;

		image {
			width: 64rpx;
			height: 18rpx;
		}
	}
</style>